
export default {
  data() {
    return {
      adType: '0',
      adObj: {
        id: '',
        adName: '',
        adUrl: coverImg,
        adType: '',
        playTimePeriod: ''
      },
      formModel: {
        list: []
      },
      rules: {
        list: [{ required: true, validator: (rule, value, callback) => {
          if (value.find(item => item.adUrl !== coverImg)) {
            return callback()
          }
          return callback('请')
        }, trigger: ['change', 'blur'] }]
      }
    }
  },
  methods: {
    loadData() {

    },
    remove(item) {
      this.$sure('确认删除？', () => {
        const param = {
          id: item.id
        }
        this.post('/deviceAd/deleteById', param).then(_ => {
          this.$info('删除成功！', this.loadData)
        }).catch(_ => {
          this.loadData()
        })
      })
    },
    handleSuccess(res, file, item) {
      const pageType = item.id ? 'update' : 'add'
      const url = pageType === 'add' ? '/deviceAd/save' : '/deviceAd/edit'
      const tip = pageType === 'add' ? '上传成功！' : '替换成功！'
      this.post(url, item).then(_ => {
        this.$info(tip, this.loadData)
      })
    },
    handleSubmit() {
      this.$refs.mntForm.validate(valid => {
        if (valid) {
          const { pageType, formModel } = this
          const param = { ...formModel }
          const url = pageType === 'add' ? '/authority/addAuthRole' : '/authority/updateAuthRole'
          const tip = pageType === 'add' ? '新增成功！' : '修改成功！'
          this.post(url, param).then(res => {
            this.$info(tip, () => {
              this.$emit('mntSuc', res)
              this.closeDialog()
            })
          })
        }
      })
    }
  },
  mounted() {

  }
}
